package com.zqxq.util;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;

public class paramSort {
	public String sortParam(List<NameValuePair> data)
	{
		StringBuffer localStringBuffer = new StringBuffer();
		Map<String, String> map=new HashMap<String, String>();
		String s = null;
		for (int i=0;i<data.size();i++){  
		    NameValuePair nameValuePair=data.get(i);  
		    map.put(nameValuePair.getName(),nameValuePair.getValue());  
		}
		try
	      {
			ArrayList<String> localObject = new ArrayList<String>(map.keySet());
	        Collections.sort(localObject);
	        //localObject = ((ArrayList<?>)localObject).iterator();
	        for (String str : localObject)
	        {
	          //String str = (String)((Iterator<?>)localObject).next();
	          localStringBuffer.append(str).append("=").append(URLEncoder.encode((String)map.get(str), "UTF-8")).append("&");
	        }
	        s = localStringBuffer.toString();
	        return s;
	      }
	      catch (Exception e)
	      {
	        e.printStackTrace();
	        return s;
	      }
		    
	}

}
